package cn.kzgg.ymcc.service.impl;

import cn.kzgg.ymcc.domain.MessageSms;
import cn.kzgg.ymcc.domain.RemoveBlack;
import cn.kzgg.ymcc.domain.User;
import cn.kzgg.ymcc.feign.pullBlack.BlackUserFeignClient;
import cn.kzgg.ymcc.mapper.MessageSmsMapper;
import cn.kzgg.ymcc.result.JSONResult;
import cn.kzgg.ymcc.service.IMessageSmsService;
import cn.kzgg.ymcc.service.IRemoveBlackService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author kzgg
 * @since 2022-07-15
 */
@Service
public class MessageSmsServiceImpl extends ServiceImpl<MessageSmsMapper, MessageSms> implements IMessageSmsService {

    @Autowired
    private MessageSmsMapper messageSmsMapper;

    @Autowired
    private IRemoveBlackService removeBlackService;

    @Autowired
    private BlackUserFeignClient blackUserFeignClient;

    @Override
    public void removeBlack(Long id) {
        MessageSms messageSms = messageSmsMapper.selectById(id);
        String ip = messageSms.getIp();
        Long userId = messageSms.getUserId();
        User user = blackUserFeignClient.goBlack(userId);
        String phone = user.getPhone();

        /*MessageSms messageSms = new MessageSms();
        RemoveBlack removeBlack = new RemoveBlack();
        //User user = new User();
        removeBlack.setIp(messageSms.getIp());
        removeBlack.setCreateTime(new Date());
        //removeBlack.setPhone(user.getPhone());
        removeBlackService.insert(removeBlack);*/
        saveUserPhone(phone,userId,ip);
        messageSmsMapper.removeBlack(id);
    }

    private void saveUserPhone(String phone,Long userId,String ip) {
        RemoveBlack removeBlack = new RemoveBlack();
        removeBlack.setPhone(phone);
        removeBlack.setUserId(userId);
        removeBlack.setIp(ip);
        removeBlack.setCreateTime(new Date());
        removeBlackService.insert(removeBlack);
    }

}
